package com.feicheng.controller.system;


import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.Distributor;
import com.feicheng.service.IFDistributorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cailongyang
 * @since 2022-01-10
 */
@RestController
@RequestMapping("/admin/distributor")
public class DistributorController {

    @Autowired
    IFDistributorService distributorService;

    @GetMapping("/info/account/ex/{account}")
    public ResultInfo checkAccountEx(@PathVariable(name="account") String account) {
        return distributorService.checkAccountEx(account);
    }

    @PostMapping("/info")
    public ResultInfo newDistributor(Distributor distributor) {
        return distributorService.newDistributor(distributor);
    }

    @DeleteMapping("/info")
    public ResultInfo deleteDistributor(Integer distributorId) {
        Distributor distributor = new Distributor();
        distributor.setDistributorId(distributorId);
        distributor.setDFlg(true);
        return distributorService.updateDistributor(distributor);
    }

    @GetMapping("/info/page")
    public ResultInfo page(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            String account,
            String name,
            String tel) {
        Distributor distributor = new Distributor();
        distributor.setAccount(account);
        distributor.setName(name);
        distributor.setTel(tel);

        return distributorService.getDistributorByPage(current, size, distributor);
    }
}
